///子弹还会与小球碰撞，所以不能使用刚体

//可以使用事件机制
let CollisionModule =require("CollisionModule");
cc.Class({
    extends: cc.Component,

    properties: {
        isAttacked:false,
        isAlive:false,

        bulletSpeed:700,
        // _rigidB:{
        //     default:null,
        //     type:cc.RigidBody,
        // }
    },

    // LIFE-CYCLE CALLBACKS:

     onLoad () {
        // this._rigidB =this.getComponent(cc.RigidBody);

     },

    SetVelocity(pos){
        this.isAlive =true;
        this._rigidB.velocity =new cc.Vec2(0,500);
        this.node.positon =pos;
    },

    start () {

    },
    onEnable(){

    },
    onDisable(){

    },
    // onBeginContact: function (contact, selfCollider, otherCollider) {
    //    let cm= otherCollider.body.node.getComponent(CollisionModule);
    //    otherCollider.body.node.emit('GetHit',{mesage:"info"});
    // },
    //
    // // 只在两个碰撞体结束接触时被调用一次
    // onEndContact: function (contact, selfCollider, otherCollider) {
    //
    // },
    //
    // // 每次将要处理碰撞体接触逻辑时被调用
    // onPreSolve: function (contact, selfCollider, otherCollider) {
    // },
    //
    // // 每次处理完碰撞体接触逻辑时被调用
    // onPostSolve: function (contact, selfCollider, otherCollider) {
    //     this.Rest();
    // },



    onCollisionEnter: function (other, self) {
        console.log('on collision enter');

        other.node.emit('GetHit',{mesage:"info"});
        this.Rest();

    },

    Rest(){
        this.isAttacked =true;
        this.isAlive =false;
        // this._rigidB.velocity =new cc.Vec2(0,0);
        this.node.active =false;
    },

    UpdateFun(dt){

        this.node.y+=dt*this.bulletSpeed;

        if(this.node.x>1100){
        this.Rest();

        }

    },
    //update (dt) {},
});
